package cz.vse.javaee.album;

/**
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: 19.4.11
 * Time: 20:51
 * To change this template use File | Settings | File Templates.
 */
public class EntityFragmentManagerClient {


    private EntityFragmentManager efm;

    public void doSomething() throws Exception {
        int photoId = 1;
        String newPhotoName = "blabla";

        PhotoWithAlbumBasicTO fragment = efm.findFragment(PhotoWithAlbumBasicTO.class, photoId);
//        JSONRender jsonRend = new JSONRender();
//        Object comp = $(fragment, jsonRend);
//        jsonRend.render(response);
//
//        ...
//
//        PhotoWithAlbumBasicTO e = (PhotoWithAlbumBasicTO)comp;
//        JSONRender jsr = (JSONRender)comp;
//        JSONRender jsr = $(comp);
//
//        $detach(fragment);
//
        fragment.setPhotoName(newPhotoName);
        efm.updateFragment(fragment);

        // Object composite = $(fragment, uiFragment, convertor);
        // XConverter converter = (XConverter)composite;
        // converter.setLastModifiedDate(dateAsText);
        // UIElement uiElem = (UIElement)composite;
        // uiElem.render(...);
    }


    public void doSomethingElse() throws Exception {
        String newPhotoName = "blabla";

        EntityFragmentManager.FragmentQuery<PhotoWithAlbumBasicTO> query = efm.createQuery(PhotoWithAlbumBasicTO.class, "p.name=:name");
        query.setParameter("name", "photo1");
        Iterable<PhotoWithAlbumBasicTO> fragments = query.getResults();

        for (PhotoWithAlbumBasicTO fragment: fragments) {
            fragment.setPhotoName(newPhotoName);
            efm.updateFragment(fragment);
        }

    }

}
